#include "stdio.h"
#include "string.h"

void changexy(int *tx,int *ty,char ch)
{
	switch (ch)
	{
		case 'N':(*tx)--;break;
		case 'S':(*tx)++;break;		 
		case 'W':(*ty)--;break;
		case 'E':(*ty)++;break;			 
	}
}


main()
{
	int map[52][52];
	int errorcode;
	int i,j,k;
	int ph,pt,n;
	int headx,heady,tailx,taily,x,y;
	char order[151],ch,inch[50];

	scanf("%d",&n);
	
	while (n!=0)
	{
		memset(map,0,sizeof(map));
		for (i=11;i<=30;i++) map[25][i]=1; /* init map*/
	
		for (i=1;i<=19;i++) order[i]='E'; /* init order */
		ph=1;pt=19;

		headx=25;heady=30; /* init worm */
		tailx=25;taily=11;
		errorcode=0;
		scanf("%s",inch);	
		for (i=1;i<=n;i++)
		{
			ch=inch[i-1];
			order[++pt]=ch;
			x=headx;y=heady;
			changexy(&x,&y,ch);			
			map[tailx][taily]=0;
			if (map[x][y]==1)
			{
				errorcode=1;
				j=i;
				break;
			}
			else if ((x==0)||(y==0)||(x==51)||(y==51))
			{
				errorcode=2;
				j=i;
				break;
			}
			else
			{
				headx=x;heady=y;
				changexy(&tailx,&taily,order[ph++]);
			}
			map[x][y]=1;
		}	
		switch (errorcode)
			{
				case 0:printf("The worm successfully made all %d moves.\n",n);
				       break;
				case 1:printf("The worm ran into itself on move %d.\n",j);
				       break;
				case 2:printf("The worm ran off the board on move %d.\n",j);
				       break;                                                 		
			}                                                                     		
		scanf("%d",&n);
	}

}
